package com.blacktech.dbu.auth.entity;

import com.blacktech.dbu.core.common.BaseEntity;
import com.blacktech.dbu.meta.entity.DbuProduct;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 用户产品权限关联实体
 *
 * @author Yanyunsong
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Entity
@Table(name = "dbu_user_product")
public class DbuUserProduct extends BaseEntity {

    /**
     * 用户ID
     */
    @NotNull(message = "用户不能为空")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id", nullable = false, foreignKey = @ForeignKey(name = "fk_user_product_user"))
    @JsonIgnore
    private DbuUser user;

    /**
     * 产品ID
     */
    @NotNull(message = "产品不能为空")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_id", nullable = false, foreignKey = @ForeignKey(name = "fk_user_product_product"))
    @JsonIgnore
    private DbuProduct product;

    /**
     * 权限级别
     * 1: OWNER - 产品负责人 (完全控制权限)
     * 2: COLLABORATOR - 产品协作员 (读写权限)
     * 3: REPORTER - 产品报告员 (只读权限)
     */
    @NotNull(message = "权限级别不能为空")
    @Min(value = 1, message = "权限级别不能小于1")
    @Column(name = "permission_level", nullable = false)
    private Integer permissionLevel;

    /**
     * 权限分配人
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "assigned_by", foreignKey = @ForeignKey(name = "fk_user_product_assigned_by"))
    @JsonIgnore
    private DbuUser assignedBy;

    /**
     * 备注说明
     */
    @Column(name = "remark", length = 500)
    private String remark;
}